package com.qidianit.mes.sys.controller;

import com.github.pagehelper.PageInfo;
import com.qidianit.mes.pojo.Result;
import com.qidianit.mes.pojo.Supplier;
import com.qidianit.mes.sys.mapper.SupplierMapper;
import com.qidianit.mes.sys.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ Description:
 * @ Author: DuYaTao
 * @ Date: 2025/9/16 - 20:04
 */

@RestController
@RequestMapping("supplier")
public class SupplierController {

    @Autowired
    private SupplierService supplierService;

    @RequestMapping("/page")
    public Result<PageInfo<Supplier>> page(Supplier supplier, @RequestParam(defaultValue = "1") int pageNum,@RequestParam(defaultValue = "10") int size){

        return supplierService.getSuppliers(supplier,pageNum,size);

    }

    @GetMapping("/code/{code}")
    public Result<Supplier> getSupplierByCode(@PathVariable String code){
        return supplierService.getSupplierByCode(code);
    }

    @PostMapping("/add")
    public Result addSupplier(@RequestBody Supplier supplier){
        return supplierService.addSupplier(supplier);
    }

    @PutMapping("/update")
    public Result updateSupplier(@RequestBody Supplier supplier){
        return supplierService.updateSupplier(supplier);
    }

    @DeleteMapping("/delete/{id}")
    public Result deleteSupplier(@PathVariable Long id){
        return supplierService.deleteSupplier(id);
    }

    @DeleteMapping("/batchDelete")
    public Result batchDeleteSupplier(Long[] id){
        return supplierService.batchDeleteSupplier(id);
    }
}
